package com.usian.skill.controller;

import com.usian.skill.common.CodeMsg;
import com.usian.skill.common.Result;
import com.usian.skill.pojo.OrderInfo;
import com.usian.skill.pojo.SkillUser;
import com.usian.skill.service.GoodsService;
import com.usian.skill.service.OrderInfoService;
import com.usian.skill.service.SkillUserService;
import com.usian.skill.vo.GoodsVo;
import com.usian.skill.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("/order")
public class OrderController {

	@Autowired
	SkillUserService userService;
	
	/*@Autowired
	RedisService redisService;*/
	
	@Autowired
	OrderInfoService orderService;
	
	@Autowired
	GoodsService goodsService;
	
    @RequestMapping("/detail")
    @ResponseBody
    public Result<OrderDetailVo> info(Model model, SkillUser user, HttpSession session,
									  @RequestParam("orderId") long orderId) {
		//获取用户的登录信息
    	String userId = session.getAttribute("userId").toString();
		if (userId==null){
			return Result.error(CodeMsg.SERVER_ERROR);
		}
		//获取订单信息
		OrderInfo orderInfo = orderService.getById(orderId);
		if (orderInfo==null){
			return Result.error(CodeMsg.ORDER_NOT_EXIST);
		}
		Long goodsId = orderInfo.getGoodsId();
		//获取商品信息
		GoodsVo goodsVo = goodsService.goodsVoById(goodsId);
		OrderDetailVo orderDetailVo = new OrderDetailVo();
		orderDetailVo.setGoods(goodsVo);
		orderDetailVo.setOrder(orderInfo);
		return Result.success(orderDetailVo);
    }
    
}
